package cz.muni.fi.pa165.hauntedhouses.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author Jaromír Benda (374289)
 */
@Entity
public class House implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Column(nullable = false)
    private String name;
    
    @Column(nullable = false)
    private String address;
    
    @Column(nullable = false)
    private String history;
    
    @Fetch(FetchMode.SUBSELECT)
    @OneToMany(mappedBy = "home",fetch= FetchType.EAGER,cascade= CascadeType.REFRESH)
    private List<Human> humans;
    
    @Fetch(FetchMode.SUBSELECT)
    @OneToMany(mappedBy = "home",fetch= FetchType.EAGER,cascade= CascadeType.REFRESH)
    private List<Ghost> ghosts;    
    
    @Column(nullable = false)
    private Integer ghostCapacity;
    
    @Column(nullable = false)
    private Integer humanCapacity;

    
    public List<Human> getHumans() {
        return humans;
    }

    public void setHumans(List<Human> humans) {
        this.humans = humans;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getHistory() {
        return history;
    }

    public void setHistory(String history) {
        this.history = history;
    }

    public List<Ghost> getGhosts() {
        return ghosts;
    }

    public void setGhosts(List<Ghost> ghosts) {
        this.ghosts = ghosts;
    }

    public Integer getGhostCapacity() {
        return ghostCapacity;
    }

    public void setGhostCapacity(Integer ghostCapacity) {
        this.ghostCapacity = ghostCapacity;
    }

    public Integer getHumanCapacity() {
        return humanCapacity;
    }

    public void setHumanCapacity(Integer humanCapacity) {
        this.humanCapacity = humanCapacity;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 83 * hash + Objects.hashCode(this.id);
        hash = 83 * hash + Objects.hashCode(this.name);
        hash = 83 * hash + Objects.hashCode(this.address);
        hash = 83 * hash + Objects.hashCode(this.history);
        hash = 83 * hash + Objects.hashCode(this.ghosts);
        hash = 83 * hash + Objects.hashCode(this.humans);
        hash = 83 * hash + Objects.hashCode(this.ghostCapacity);
        hash = 83 * hash + Objects.hashCode(this.humanCapacity);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final House other = (House) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        if (!Objects.equals(this.address, other.address)) {
            return false;
        }
        if (!Objects.equals(this.history, other.history)) {
            return false;
        }
        if (!Objects.equals(new ArrayList<Ghost>().addAll(this.ghosts), new ArrayList<Ghost>().addAll(other.ghosts))) {
            return false;
        }
        if (!Objects.equals(new ArrayList<Human>().addAll(this.humans), new ArrayList<Human>().addAll(other.humans))) {
            return false;
        }
        if (!Objects.equals(this.ghostCapacity, other.ghostCapacity)) {
            return false;
        }
        if (!Objects.equals(this.humanCapacity, other.humanCapacity)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "House{" + "id=" + id + ", name=" + name + ", address=" + address + ", history=" + history 
                + ", ghostCapacity=" + ghostCapacity + ", humanCapacity=" + humanCapacity + '}';
    }
}
